package com.example.computer_component_manager.ui.main

import android.content.Context
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.example.computer_component_manager.R
import com.example.computer_component_manager.fragment.impl.CpuFragment
import com.example.computer_component_manager.fragment.impl.GpuFragment

/**
 * A [FragmentPagerAdapter] that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
class SectionsPagerAdapter(private val context: Context, fm: FragmentManager) :
    FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
    private val tabTitles = arrayOf(
        R.string.cpu_manager,
        R.string.gpu_manager
    )

    // 根据tab不同位置呈现不同的内容
    override fun getItem(position: Int): Fragment {
        when (position) {
            1 -> return GpuFragment()
        }
        return CpuFragment()
    }

    override fun getPageTitle(position: Int): CharSequence =
        context.resources.getString(tabTitles[position])

    override fun getCount() = tabTitles.size
}